"use strict";
cc._RF.push(module, 'c00f0k+gIZPppiKuAn3B2SQ', 'TipsPage');
// scripts/Game/Page/TipsPage.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var gameEngine_1 = require("../../engines/gameEngine");
var PageBase_1 = require("../Base/PageBase");
var Enum_1 = require("../Enum");
var MainRoot_1 = require("../MainRoot");
var tipsPageSpNode_1 = require("../Obj/tipsPageSpNode");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property, menu = _a.menu, disallowMultiple = _a.disallowMultiple;
var TipsPage = /** @class */ (function (_super) {
    __extends(TipsPage, _super);
    function TipsPage() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.tipsShow = null;
        _this.img = null;
        _this.boardFrame = null;
        _this.rewardBtn = null;
        _this.tipNode = null;
        _this.answerNode = null;
        _this.spScaleNode = null;
        _this.tipsAndAnswer = "";
        _this.autoShowSp = false;
        _this.tipsAndAnswerLength = 0;
        _this.answerScaleNode = null;
        _this.answerNodeCopy = null;
        return _this;
    }
    TipsPage.prototype.OnPageOpen = function (prams) {
        return __awaiter(this, void 0, void 0, function () {
            var tipsStr, tipAndAnswer, tipsType, tipFontLength, tipNode, sp_1, i, aLabel, needHang2, i, aLabel, answerStr, j;
            return __generator(this, function (_a) {
                _super.prototype.OnPageOpen.call(this, prams);
                tipsStr = prams.tips;
                tipAndAnswer = tipsStr.split("#");
                this.tipsAndAnswer = tipAndAnswer[1];
                this.tipsAndAnswerLength = tipAndAnswer[0].length;
                tipsType = tipAndAnswer[0].includes("$h");
                tipAndAnswer[0] = tipAndAnswer[0].replace("$h", "");
                tipFontLength = 10;
                tipNode = this.tipNode.getChildByName("lbSmallLayout");
                if (tipsType) {
                    tipNode = this.tipNode.getChildByName("lbHLayout");
                }
                else if (tipAndAnswer[0].length > 40) {
                    tipNode = this.tipNode.getChildByName("lbBigLayout");
                    tipFontLength = 16;
                }
                if (tipAndAnswer[0].indexOf("/") > -1) {
                    sp_1 = this.tipNode.getChildByName("mask").getChildByName("sp");
                    sp_1.active = true;
                    for (i = 0; i < tipNode.childrenCount; i++) {
                        aLabel = tipNode.getChildByName("Label" + i);
                        aLabel.active = false;
                    }
                    cc.resources.load(this.tipsAndAnswer, cc.SpriteFrame, function (err, asset) {
                        if (err) {
                            console.log("加载提示图片出错");
                            return;
                        }
                        sp_1.getComponent(cc.Sprite).spriteFrame = asset;
                        var width = asset.getTexture().width;
                        var height = asset.getTexture().height;
                        var wRadio = 208 / width;
                        var hRadio = 440 / height;
                        var radio = 1;
                        if (wRadio > hRadio) {
                            radio = wRadio;
                        }
                        else {
                            radio = hRadio;
                        }
                        sp_1.width = sp_1.width * radio;
                        sp_1.height = sp_1.height * radio;
                    });
                }
                else {
                    tipNode.active = true;
                    if (tipsType) {
                        tipNode.children[0].getComponent(cc.Label).string = tipAndAnswer[0];
                    }
                    else {
                        needHang2 = Math.ceil(tipAndAnswer[0].length / tipFontLength);
                        for (i = 0; i < tipNode.childrenCount; i++) {
                            aLabel = tipNode.getChildByName("Label" + i);
                            aLabel.active = i < needHang2;
                            answerStr = "";
                            for (j = i * tipFontLength; j < i * tipFontLength + tipFontLength; j++) {
                                if (tipAndAnswer[0][j])
                                    answerStr += tipAndAnswer[0][j];
                            }
                            aLabel.getComponent(cc.Label).string = answerStr;
                            if (i >= needHang2) {
                                aLabel.active = false;
                            }
                            else {
                                aLabel.active = true;
                            }
                        }
                    }
                }
                // this.tipNode.getChildByName("Label").getComponent(cc.Label).string = tipAndAnswer[0];
                // let answerType = tipAndAnswer[1].includes("$h");
                // tipAndAnswer[1] = tipAndAnswer[1].replace("$h","");
                // this.autoShowSp = tipAndAnswer[1].includes("!");
                // tipAndAnswer[1] = tipAndAnswer[1].replace("!","");
                // let answerNode = this.answerNode.getChildByName("lbSmallLayout");
                // let answerFontLength = 10;
                // if(answerType){
                //     answerNode = this.answerNode.getChildByName("lbHLayout")
                // }else if(tipAndAnswer[1].length>40) {
                //     answerNode = this.answerNode.getChildByName("lbBigLayout");
                //     answerFontLength = 16;
                // }
                // if (tipAndAnswer[1].indexOf("/") > -1) {
                //     this.answerNode.getComponent(cc.Button).interactable = false;
                //     const sp = this.answerNode.getChildByName("mask").getChildByName("sp");
                //     sp.active = true;
                //     for (let i = 0; i < answerNode.childrenCount; i++) {
                //         let aLabel = answerNode.getChildByName("Label" + i);
                //         aLabel.active = false;
                //     }
                //     cc.resources.load(tipAndAnswer[1], cc.SpriteFrame, (err, asset: cc.SpriteFrame) => {
                //         if (err) {
                //             console.log("加载提示图片出错");
                //             return;
                //         }
                //         sp.getComponent(cc.Sprite).spriteFrame = asset;
                //         let width = asset.getTexture().width;
                //         let height = asset.getTexture().height;
                //         let wRadio:number = 208/width;
                //         let hRadio:number = 440/height;
                //         let radio = 1;
                //         if(wRadio>hRadio){
                //             radio = wRadio;
                //         }else{
                //             radio = hRadio;
                //         }
                //         sp.width = sp.width*radio;
                //         sp.height = sp.height*radio;
                //     });
                // } else {
                //     answerNode.active = true;
                //     if(answerType){
                //         answerNode.children[0].getComponent(cc.Label).string = tipAndAnswer[1];
                //     }else{
                //         let needHang: number = Math.ceil(tipAndAnswer[1].length / answerFontLength);
                //         for (let i = 0; i < answerNode.childrenCount; i++) {
                //             let aLabel = answerNode.getChildByName("Label" + i);
                //             aLabel.active = i < needHang;
                //             let answerStr: string = "";
                //             for (let j = i * answerFontLength; j < i * answerFontLength + answerFontLength; j++) {
                //                 if (tipAndAnswer[1][j])
                //                     answerStr += tipAndAnswer[1][j];
                //             }
                //             aLabel.getComponent(cc.Label).string = answerStr;
                //         }
                //     }
                // }
                // let level = mainRoot.LevelSystem.GetCurrLevel(this.m_mode);
                // const content: INormalLevelStruct = mainRoot.LevelSystem.GetSignleLevelInfo(this.m_mode, level);
                // if(content.name == "Level_66"){
                // }
                // console.warn('获取1', mainRoot.GotTips);
                this.node.getChildByName("Content").getChildByName("ad1").active = false; //!mainRoot.GotTips;
                // console.error(mainRoot.GotTips)
                // this.tipNode.opacity = mainRoot.GotTips ? 255 : 0;
                this.node.getChildByName("Content").getChildByName("ad3").active = false; //!mainRoot.GotAnswer && !mainRoot.GotTips;
                this.node.getChildByName("Content").getChildByName("ad2").active = false; // !mainRoot.GotAnswer && mainRoot.GotTips;
                // this.answerNode.opacity = mainRoot.GotAnswer ? 255 : 0;
                gameEngine_1.default.emit(Enum_1.GAME_EVENT.GAME_PAUSE);
                return [2 /*return*/];
            });
        });
    };
    TipsPage.prototype.onClickTip = function () {
        var _this = this;
        cc.game.pause();
        gameEngine_1.services().miniGameSrv.getAppApiInstance().loadAndShowVideoAd(function () {
            _this.tipNode.opacity = 255;
            _this.node.getChildByName("Content").getChildByName("ad1").active = false;
            _this.node.getChildByName("Content").getChildByName("ad3").active = false;
            _this.node.getChildByName("Content").getChildByName("ad2").active = true;
            gameEngine_1.default.emit(Enum_1.GAME_EVENT.ON_TIPS_GOT);
            MainRoot_1.default.GotTips = true;
        }, function () {
            cc.game.resume();
        }, function () {
            cc.game.resume();
        }, "看视频获取提示");
    };
    TipsPage.prototype.onClickAnswer = function () {
        var _this = this;
        if (this.tipNode.opacity != 255) {
            gameEngine_1.modules().uiControlModule.showMessageBox("请先解锁提示");
            return;
        }
        if (MainRoot_1.default.GotAnswer) {
            return;
        }
        cc.game.pause();
        gameEngine_1.services().miniGameSrv.getAppApiInstance().loadAndShowVideoAd(function () {
            var level = MainRoot_1.default.LevelSystem.GetCurrLevel(_this.m_mode);
            var content = MainRoot_1.default.LevelSystem.GetSignleLevelInfo(_this.m_mode, level);
            _this.answerNode.opacity = 255;
            _this.node.getChildByName("Content").getChildByName("ad2").active = false;
            gameEngine_1.default.emit(Enum_1.GAME_EVENT.ON_ANSWER_GOT);
            MainRoot_1.default.GotAnswer = true;
            gameEngine_1.default.emit('level-to-hint');
            if (_this.autoShowSp) {
                _this.onShowSp(null, "answer");
            }
        }, function () {
            cc.game.resume();
        }, function () {
            cc.game.resume();
        }, "看视频获取答案");
    };
    TipsPage.prototype.OnRewardBtn = function () {
        PageBase_1.default.isPlaySound = false;
        gameEngine_1.default.emit(Enum_1.GAME_EVENT.GAME_RESUME);
        gameEngine_1.managers().soundMgr.playSound("mainSound/anNiu");
        this.onReward && this.onReward();
        this.ClosePage();
    };
    TipsPage.prototype.onShowSp = function (e, type) {
        var spTexture = null;
        switch (type) {
            case "tip": {
                spTexture = this.tipNode.getChildByName("mask").getChildByName("sp").getComponent(cc.Sprite).spriteFrame.clone();
                break;
            }
            case "answer": {
                var sp = this.answerNode.getChildByName("mask").getChildByName("sp").getComponent(cc.Sprite).spriteFrame;
                if (sp)
                    spTexture = sp.clone();
                break;
            }
        }
        if (spTexture) {
            this.spScaleNode.active = true;
            this.spScaleNode.opacity = 0;
            var spNode = this.spScaleNode.getChildByName("sp");
            spNode.setPosition(cc.v2(0, 0));
            spNode.getComponent(cc.Sprite).spriteFrame = spTexture;
            var width = spTexture.getTexture().width;
            var height = spTexture.getTexture().height;
            var canvasWidth = this.spScaleNode.width;
            var radio = canvasWidth / width;
            spNode.width = width * radio;
            spNode.height = height * radio;
            this.spScaleNode.getChildByName("bg").active = true;
            cc.tween(this.spScaleNode).to(0.5, { opacity: 255 }).start();
        }
    };
    TipsPage.prototype.closeSpScale = function () {
        this.spScaleNode.active = false;
    };
    TipsPage.prototype.onAnswerClick = function () {
        this.answerNodeCopy = cc.instantiate(this.answerNode);
        this.answerScaleNode.addChild(this.answerNodeCopy);
        this.answerNodeCopy.scale = 2;
        var ts = this.answerNodeCopy.addComponent(tipsPageSpNode_1.default);
        this.answerNodeCopy.removeComponent(cc.Button);
        ts.tipsPage = this;
        ts.scaleMul = 0.2;
        ts.maxScale = 3;
        this.answerScaleNode.active = true;
        this.answerNodeCopy.setPosition(cc.v2(0, 0));
        this.answerScaleNode.getChildByName("bg").active = true;
        cc.tween(this.answerScaleNode).to(0.5, { opacity: 255 }).start();
    };
    TipsPage.prototype.closeAnswerScale = function () {
        var _a, _b;
        this.answerNodeCopy && ((_a = this.answerNodeCopy) === null || _a === void 0 ? void 0 : _a.destroy());
        this.answerNodeCopy && ((_b = this.answerNodeCopy) === null || _b === void 0 ? void 0 : _b.removeFromParent());
        this.answerNodeCopy = null;
        this.answerScaleNode.active = false;
    };
    __decorate([
        property({ type: cc.Label, displayName: "提示展示" })
    ], TipsPage.prototype, "tipsShow", void 0);
    __decorate([
        property({ type: cc.Sprite, displayName: "提示加载的图片" })
    ], TipsPage.prototype, "img", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "底板框" })
    ], TipsPage.prototype, "boardFrame", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "领取按钮" })
    ], TipsPage.prototype, "rewardBtn", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "提示" })
    ], TipsPage.prototype, "tipNode", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "答案" })
    ], TipsPage.prototype, "answerNode", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "spScaleNode" })
    ], TipsPage.prototype, "spScaleNode", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "spScaleNode" })
    ], TipsPage.prototype, "answerScaleNode", void 0);
    TipsPage = __decorate([
        ccclass,
        disallowMultiple,
        menu('游戏页面/提示页面')
    ], TipsPage);
    return TipsPage;
}(PageBase_1.default));
exports.default = TipsPage;

cc._RF.pop();